define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wechatuser/user/index',
                    add_url: 'wechatuser/user/add',
                    edit_url: 'wechatuser/user/edit',
                    del_url: 'wechatuser/user/del',
                    multi_url: 'wechatuser/user/multi',
                    table: 'wechat_user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
						{field: 'id', title: __('Id')},
						{field: 'userid', title: __('Userid')},
						{field: 'uid', title: __('Uid')},
						{field: 'name', title: __('Name')},
						{field: 'english_name', title: __('English_name')}, 
						{field: 'mobile', title: __('Mobile')},
						{field: 'email', title: __('Email')},
						{field: 'department_text', title: __('Department'), operate:false, formatter: Table.api.formatter.label},
						//{field: 'department', title: __('Department')},
						{field: 'position_text', title: __('Position'), operate:false, formatter: Table.api.formatter.label},
						{field: 'gender', title: __('Gender'), searchList: {"1":__('Gender 1'),"2":__('Gender 2')}, formatter: Table.api.formatter.normal},
						{field: 'telephone', title: __('Telephone')},
						{field: 'isleader', title: __('Isleader'), searchList: {"1":__('Isleader 1'),"0":__('Isleader 0')}, formatter: Table.api.formatter.normal},
						//{field: 'avatar_mediaid', title: __('Avatar_mediaid')},
						//{field: 'avatar_url', title: __('Avatar_url')},
						{field: 'enable', title: __('Enable'), searchList: {"1":__('Enable 1'),"0":__('Enable 0')}, formatter: Table.api.formatter.normal},
						//{field: 'delete_status', title: __('Delete_status')},
						{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
						{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
						{field: 'publish', title: __('Publish')},
						{field: 'z_publish', title: __('Z_publish')},
						{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});